﻿using Microsoft.EntityFrameworkCore;
using SmartParking.Entities;
using SmartParking.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartParking.Service
{
    public class UserService : BaseService, IUserService
    {
        public UserService(DbContext context)
            : base(context)
        {

        }

        public IEnumerable<SysUser> GetUsers(string key)
        {
            return this.Query<SysUser>(u => string.IsNullOrWhiteSpace(key) || u.UserName.Contains(key) || u.RealName.Contains(key));
        }

        public SysUser Login(string username, string password)
        {
            return this.Query<SysUser>(u => u.UserName == username && u.Password == password)
                 .FirstOrDefault();
        }

        public bool CheckUserName(string userName)
        {
            return this.Query<SysUser>(u => u.UserName == userName).Count() > 0;
        }
    }
}
